import threading
import requests
from lxml import etree


class recommendMedicine:
    def __init__(self):
        self.headers = {
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36',
            'cookie': '__finger=8c6cf3c4db94a8d5b1ea65208b7a06eb; Hm_lvt_f46dd4cc550b93aefde9b00265bb533d=1616479087; UM_distinctid=1785da96b84b0d-0b10b9c44101e6-5771031-1fa400-1785da96b85be5; CNZZDATA899409=cnzz_eid%3D1562633242-1616475837-https%253A%252F%252Fwww.sogou.com%252F%26ntime%3D1616475837; Hm_lvt_efd3be6e24f6aa90edbcdea9b260aac6=1616479088; CNZZDATA953100=cnzz_eid%3D1999569600-1616478788-https%253A%252F%252Fwww.sogou.com%252F%26ntime%3D1616478788; __asc=51716daf1785da96fd25a0658ef; __auc=51716daf1785da96fd25a0658ef; Hm_lpvt_f46dd4cc550b93aefde9b00265bb533d=1616479172; Hm_lpvt_efd3be6e24f6aa90edbcdea9b260aac6=1616479172'
        }
        self.base_url = 'https://ypk.familydoctor.com.cn/'

    # 请求网页
    def connect_url(self, url):
        response = requests.get(url, headers=self.headers)
        text = response.content.decode('utf-8')
        html = etree.HTML(text)
        return html
    # //div[@id="tabContent1_0"]/ul/li//a           名字
    #  //div[@id="tabContent1_0"]/ul//a/img/@src    图片链接

    # 返回图片链接
    def msgurl(self, url, num):
        html = self.connect_url(url)
        msg_url = html.xpath('//div[@id="tabContent1_0"]/ul//a/img/@src'.format(num))[0].strip()
        return msg_url

    # def msgname(self,):